package com.gc.gc.duty.login.control;

import com.gc.gc.duty.login.entity.MenuLevelEntity;
import com.gc.gc.user.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Locale;

@Controller
@RequestMapping("/login")
public class LoginController {
    private Logger logger =  LogManager.getLogger(this.getClass().getName());
    @Resource
    private UserService userService;
    @RequestMapping("/login")
    public String login(HttpServletRequest request, Model model){
        String siteLanguage = request.getParameter("siteLanguage");
        model.addAttribute("siteLanguage",siteLanguage);
        return"/login/login";
    }
    @RequestMapping("/main")
    public String main(){
        return "redirect:/";
    }

    @RequestMapping("/queryMenuInfoByLang")
    @ResponseBody
    public List<MenuLevelEntity> queryMenuInfoByLang(){
        Locale locale = LocaleContextHolder.getLocale();
        List<MenuLevelEntity> queryMenuInfoByLang =userService.queryMenuInfoByLang(locale.toString());
        return  queryMenuInfoByLang;
    }
}
